package MainControl;

import java.io.*;

public class DataToText {
    public void addtotxt(String data) throws IOException {
       /* FileWriter fw=null;
        try {
            File f=new File("E:\\data.txt");
            fw=new FileWriter(f,true);

        }catch (Exception e){
            e.printStackTrace();
        }
        PrintWriter pw=new PrintWriter(fw);
        pw.println(data);
        pw.flush();
        try {
            fw.flush();
            pw.close();
        }catch (Exception e){
            e.printStackTrace();
        }*/
        String path = "E://nihao.txt";
        File file = new File(path);
        if (file.exists()) {
        } else {
            file.createNewFile();
        }
        // 向文件中写数据
        BufferedWriter out_write = new BufferedWriter(new FileWriter(file, true));
        out_write.write(data + "\r\n");
        out_write.flush();
        out_write.close();
    }
}
